import { nextTick } from 'vue';
import router from '@/router';
import { useTitle } from '@vueuse/core';
import { WEB_TITLE } from '@/constant';

/**
 * 根据路由 meta.title 设置浏览器标题
 */
export function setTitleFromRoute() {
    if (typeof router.currentRoute.value.meta.title !== 'string') {
        return;
    }
    nextTick(() => {
        let webTitle = router.currentRoute.value.meta.title as string;
        const title = useTitle();
        title.value = `${webTitle}-${WEB_TITLE}`;
    }).then();
}
